﻿#include "view.h"

void myNotePad::toggleSidebarActionSlot() {//显示/隐藏边框实现

	QDockWidget* DocW = this->findChild<QDockWidget*>("DocW");
	QTabWidget* TabW = this->findChild<QTabWidget*>("TabW");

		// 设置窗口属性为无边框
	DocW->setVisible(false);
	TabW->setVisible(false);
	side_flag++;
	if (side_flag%2!=0) {
		DocW->setVisible(true);
		TabW->setVisible(true);// 恢复窗口的初始属性

	}
		show();
}

void myNotePad::outlineActionSlot() {//大纲实现

}

void myNotePad::searchActionSlot() {//搜索实现

}



void myNotePad::soureCodeModeActionSlot() {//源代码模式实现
	iQTextCursor cursor = mainText->textCursor();
	int Position = cursor.QTextCursor::position();
	{
		QSignalBlocker blocker(mainText->document());
		this->getViewMode().base = !this->getViewMode().base;
		mainText->view_mode = this->getViewMode();
		
		cursor.beginEditBlock();

		QString string;
		if (!this->getViewMode().base) {
			QSignalBlocker blocker1(cursor.document());
			cursor.select(QTextCursor::BlockUnderCursor);
			QString array = cursor.selection().toMarkdown();

			// 移动光标到文本块的起始位置
			cursor.movePosition(QTextCursor::StartOfBlock);
			// 扩展光标选区，直到文本块的结束位置
			cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
			cursor.insertMarkdown(array);
			cursor.setPosition(Position);
			mainText->setTextCursor(cursor);
			string = mainText->toMarkdown();
			qDebug() << "allInMD:" << string;
			iTextEdit::loadtext(string, *mainText, this->getViewMode());
			cursor.endEditBlock();
			return;
		}
		/*if(this->getViewMode().base)
			string = mainText->toPlainText();
		else if(!this->getViewMode().base)
			string = mainText->toMarkdown();*/
		{
			//QSignalBlocker blocker1(cursor.document());
			string = mainText->toMarkdown();
			iTextEdit::loadtext(string, *mainText, this->getViewMode());
			
		}

		cursor.endEditBlock();
	}
	cursor.setPosition(Position);
	mainText->setTextCursor(cursor);
}
void myNotePad::focusModeActionSlot() {//专注模式实现

}

void myNotePad::typewriterModeActionSlot() {//打字机模式实现

}

void myNotePad::actualSizeActionSlot() {//实际大小实现

}

void myNotePad::zoomInActionSlot() {//放大实现

}

void myNotePad::zoomOutActionSlot() {//缩小实现

}